import { VuexModule, Module, getModule, Mutation } from 'vuex-module-decorators'
// import api from '@/core/api'
import type { IArea } from '@/common/services/public'
import store from '@/store'

export interface IAreaState {
}
@Module({
  dynamic: true,
  namespaced: true,
  store,
  name: 'area'
})
class Area extends VuexModule implements IAreaState {

  public currentSelectArea: Partial<IArea> = {}
  public currentAreas: IArea[] = []

  get isLargeScreen() {
    return window.screen.width > 1920
  }

  /**
   * 更新当前选择的地区数据
   *
   * @param {Partial<IArea>} [area={}]
   * @memberof App
   */
  @Mutation
  public SET_CURRENT_SELECT_AREA(area: Partial<IArea> = {}) {
    this.currentSelectArea = Object.assign(this.currentSelectArea, area)
  }

  /**
   * 更新当前已知区域数据
   *
   * @param {IArea[]} areas
   * @memberof App
   */
  @Mutation
  public SET_CURRENT_AREAS(areas: IArea[]) {
    this.currentAreas = areas
  }

  /**
   * 清理地区数据
   *
   * @memberof Area
   */
  @Mutation
  public CLEAR_AREA_DATA() {
    this.currentAreas = []
    this.currentSelectArea = {}
  }
}

export const areaModule = getModule(Area)

export default Area
